package com.gnerv.sylvanas.business.manage.logic;

import com.gnerv.sylvanas.framework.common.model.RestResult;
import com.gnerv.sylvanas.framework.core.BaseUkIdGenerate;
import com.gnerv.sylvanas.business.manage.model.bo.ApiGroupBO;
import com.gnerv.sylvanas.business.manage.model.dto.ApiGroupCreateDTO;
import com.gnerv.sylvanas.business.manage.model.dto.ApiGroupDTO;
import com.gnerv.sylvanas.business.manage.model.dto.ApiGroupTreeDTO;
import com.gnerv.sylvanas.business.manage.model.dto.ApiGroupTreeDetailsDTO;
import com.gnerv.sylvanas.business.manage.model.dto.ApiGroupUpdateDTO;
import com.gnerv.sylvanas.business.manage.operation.ApiGroupOperationService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Gnerv LiGen
 */
@Slf4j
@Service
@AllArgsConstructor
public class ApiGroupLogicService  {

    private final ApiGroupOperationService apiGroupOperationService;
    private final BaseUkIdGenerate baseUkIdGenerate;

    
    public RestResult<Void> create(ApiGroupCreateDTO apiGroupCreateDTO) {
        ApiGroupBO apiGroupBO = apiGroupCreateDTO.toApiGroupBO();
        apiGroupBO.setUkId(baseUkIdGenerate.generate());
        apiGroupOperationService.create(apiGroupBO);
        return RestResult.ok();
    }

    
    public RestResult<Void> deleteByUkId(String ukId) {
        apiGroupOperationService.deleteByUkId(ukId);
        return RestResult.ok();
    }

    
    public RestResult<Void> updateByUkId(ApiGroupUpdateDTO apiGroupUpdateDTO) {
        ApiGroupBO apiGroupBO = apiGroupUpdateDTO.toApiGroupBO();
        apiGroupOperationService.updateByUkId(apiGroupBO);
        return RestResult.ok();
    }

    
    public RestResult<ApiGroupDTO> selectByUkId(String ukId) {
        ApiGroupDTO apiGroupDTO = apiGroupOperationService.selectByUkId(ukId);
        return RestResult.ok(apiGroupDTO);
    }

    
    public RestResult<List<ApiGroupDTO>> selectListByName(String name, int limitStart, int limitSize) {
        List<ApiGroupDTO> apiGroupDTOList = apiGroupOperationService.selectListByName(name, limitStart, limitSize);
        int count = apiGroupOperationService.selectCountByName(name);
        return RestResult.ok(apiGroupDTOList).page(count, limitStart, limitSize);
    }

    
    public RestResult<List<ApiGroupTreeDTO>> selectListTreeByParentUkId(String parentUkId) {
        List<ApiGroupTreeDTO> apiGroupTreeDTOList = apiGroupOperationService.selectListTreeByParentUkId(parentUkId);
        return RestResult.ok(apiGroupTreeDTOList);
    }

    
    public RestResult<List<ApiGroupTreeDetailsDTO>> selectListTreeDetailsByParentUkId(String parentUkId) {
        List<ApiGroupTreeDetailsDTO> apiGroupTreeDetailsDTOList = apiGroupOperationService.selectListTreeDetailsByParentUkId(parentUkId);
        return RestResult.ok(apiGroupTreeDetailsDTOList);
    }

}
